package com.radar.common;

import ucar.ma2.DataType;
import ucar.nc2.*;

import java.util.List;

public enum ProductType {
    REF("Base Reflectivity", "dbz"),
    REFGRAY("Base Reflectivity gray", "dbz"),
    VEL("Base Velocity", "m/s"),
    SW("Spectral Width", ""),
    RF("", ""),
    ZDR("Differential Ref.", "dB"),
    PHI("Differential Phase", "deg"),
    RHO("Correlation Coe.", ""),
    TREF("Total Reflectivity", "dBZ"),
    KDP("Spec. Diff. Phase", "deg/km"),
    VILD("VIL Density", "g/m**3"),
    HCL("Hydrometeor Class", ""),
    OHP("One-Hour Precip.", "mm"),
    CR("Composite Ref.", "dBZ"),
    ET("Echo Tops", "km"),
    VIL("V Integrated Liquid", "kg/m**2");

    private String fullName;

    private String unit;

    public String getFullName() {
        return fullName;
    }

    public String getUnit() {
        return unit;
    }

    public Variable writeVariable(NetcdfFileWriter write, NetcdfFile netcdfFile, List<Dimension> dimensions){
        Variable variable = netcdfFile.findVariable(this.name());
        if(variable != null){
            return variable;
        }
        variable = write.addVariable(null, this.name(), DataType.BYTE, dimensions);
        variable.addAttribute(new Attribute("missing_value", (byte)-128));
        variable.addAttribute(new Attribute("add_offset", this == ProductType.VEL || this == ProductType.SW ? 62.5 : 32.5));
        variable.addAttribute(new Attribute("scale_factor", 2.0));
        variable.addAttribute(new Attribute("full_name",this.getFullName()));
        variable.addAttribute(new Attribute("units",this.getUnit()));
        return variable;
    }

    ProductType(String fullName, String unit) {
        this.fullName = fullName;
        this.unit = unit;
    }

    @Override
    public String toString() {
        return this.fullName + " (" + this.unit + ")";
    }
}
